package com.fei.fpmall.malladmin.controller;

import javax.annotation.Resource;

import com.fei.fpmall.core.utils.Const;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fei.fpmall.core.annotation.Before;
import com.fei.fpmall.malladmin.interceptor.MallAdminLoginInterceptor;
import com.fei.fpmall.service.basemanage.IUsersService;

import java.util.Properties;


/**
 * @description：首页控制器
 * @author：felix
 * @date：2017年9月12日 下午8:56:58
 */
@Controller
@RequestMapping("/")
@Before(MallAdminLoginInterceptor.class)
public class HomeController extends BaseController {
	
	@Resource
    private IUsersService userService;
	
	
	@RequestMapping(value="index",method = RequestMethod.GET)
    public String index(Model model) {
        return "index";
    }
	
	@RequestMapping(value="/user/{uid}",method = RequestMethod.GET)
	@ResponseBody
	public Object User(@PathVariable("uid") Integer uid) {
		com.fei.fpmall.entity.basemanage.User responseModel=userService.queryObject(uid);
		return responseModel;
	}

	//我的桌面
	@RequestMapping(value="/home/myDeskTop",method = RequestMethod.GET)
	public String myDeskTop(Model model) {
		Properties props = System.getProperties();
		//java版本
		String javaVersion = props.getProperty("java.version");
		//操作系统名称
		String osName = props.getProperty("os.name") + props.getProperty("os.version");
		//用户的主目录
		String userHome = props.getProperty("user.home");
		//用户的当前工作目录
		String userDir = props.getProperty("user.dir");
		//服务器IP
		String serverIP = request.getLocalAddr();
		//客户端IP
		String clientIP = request.getRemoteHost();
		//WEB服务器
		String webVersion = request.getServletContext().getServerInfo();
		//CPU个数
		String cpu = Runtime.getRuntime().availableProcessors() + "核";
		//虚拟机内存总量
		String totalMemory = (Runtime.getRuntime().totalMemory()/1024/1024) + "M";
		//虚拟机空闲内存量
		String freeMemory = (Runtime.getRuntime().freeMemory()/1024/1024) + "M";
		//虚拟机使用的最大内存量
		String maxMemory = (Runtime.getRuntime().maxMemory()/1024/1024) + "M";

		//网站根目录
		String webRootPath = request.getSession().getServletContext().getRealPath("");
		model.addAttribute("javaVersion",javaVersion);
		model.addAttribute("osName",osName);
		model.addAttribute("userHome",userHome);
		model.addAttribute("userDir",userDir);
		model.addAttribute("clientIP",clientIP);
		model.addAttribute("serverIP",serverIP);
		model.addAttribute("cpu",cpu);
		model.addAttribute("totalMemory",totalMemory);
		model.addAttribute("freeMemory",freeMemory);
		model.addAttribute("maxMemory",maxMemory);
		model.addAttribute("webVersion",webVersion);
		model.addAttribute("webRootPath",webRootPath);
		model.addAttribute("systemVersion", Const.SYSTEM_VERSION);
		model.addAttribute("systemName",Const.SYSTEM_NAME);
		model.addAttribute("systemUpdateTime",Const.SYSTEM_UPDATE_TIME);

		return "myDeskTop";
	}
}
